<?php

namespace app\fuck\controller;

use cmf\controller\BaseController;
use app\fuck\model\WhzxModel;

/**
 * Class SheetController
 * @package app\fuck\controller
 * @adminMenuRoot(
 *     'name'   =>'批量数据录入',
 *     'action' =>'default',
 *     'parent' =>'',
 *     'display'=> true,
 *     'order'  => 30,
 *     'icon'   =>'th',
 *     'remark' =>'批量数据录入'
 * )
 */
class WhzxController extends BaseController
{

    /**
     * 武汉中学七年级课表转换
     * @adminMenu(
     *     'name'   => '武汉中学七年级课表转换',
     *     'parent' => 'default',
     *     'display'=> true,
     *     'hasView'=> true,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '武汉中学七年级课表转换',
     *     'param'  => ''
     * )
     * @return mixed
     */
    public function Q11c1kb()
    {
        return $this->fetch();
    }

    public function Q11c2kb()
    {
        return $this->fetch();
    }

    public function Q11c3kb()
    {
        return $this->fetch();
    }

    /**
     *  初一数据老师表和其它数据表POST
     */
    public function post_c1ls()
    {
        $ls = $this->request->param('postls/a', []);
        $sj = $this->request->param('postsj/a', []);
        //var_dump($d);

        if (empty($ls)) {
            $this->error("没有老师数据！");
        }
        if (empty($sj)) {
            $this->error("没有学年学期、周次、星期等数据！");
        }

        $njmc = 7;
        $xnxq = "";     //学年学期
        $xq = "";         //星期几
        $zc = "";             //周次

        if (isset($sj['xnxq']))          $xnxq = $sj['xnxq'];
        if (isset($sj['xq']))            $xq = $sj['xq'];
        if (isset($sj['zc']))            $zc = $sj['zc'];

        $m = new WhzxModel();
        $ret = $m->save_kc_ls($ls, $njmc, '武湖中学', $xnxq, $zc, $xq);
        //var_dump($ls);

        //保存老师到数据库
        $v_ls = array();
        foreach ($ls as $k1 => $v1) {
            if ($k1 == 0) {
                continue;
            }     //第1行数据是标题行，不要
            //var_dump($v1);
            foreach ($v1 as $k2 => $v2) {
                if ($k2 == 'bj' || $k2 == 'bzr' || $k2 == 'jswz') {
                    continue;
                }    //第1列和2列是班级名称和班主任，不要
                //var_dump($k2);
                $v_ls[] = $v2;  //保存老师到数据库里
            }
        }
        //var_dump($v_ls);
        $ret = $m->save_ls($v_ls, $njmc, '武湖中学', $xnxq, $zc, $xq);

        $res = ["code" => 1, "data" => [$ls, $sj], "msg" => ""];

        if ($res['code']) {
            $this->success($res['msg'], '', $res['data']);
        } else {
            $this->error($res['msg'], '', $res['data']);
        }
    }
    /**
     *  初一数据课表POST，一行一行地取数据
     */
    public function post_c1kb()
    {
        $kb = $this->request->param('postkb_row/a', []);        //课表是一行一行地取，否则数据太大有丢失Post数据情况
        $sj = $this->request->param('postsj/a', []);
        //var_dump($kb);

        if (empty($kb)) {
            $this->error("没有课表数据！");
        }
        if (empty($sj)) {
            $this->error("没有学年学期、周次、星期等数据！");
        }

        $njmc = 7;
        $xxmc = '武湖中学';
        $xnxq = "";     //学年学期
        $xq = "";         //星期几
        $zc = "";             //周次
        if (isset($sj['xnxq']))          $xnxq = $sj['xnxq'];
        if (isset($sj['xq']))            $xq = $sj['xq'];
        if (isset($sj['zc']))            $zc = $sj['zc'];
        //var_dump($kb);

        $m = new WhzxModel();
        $res = $m->save_kb_bj($kb, $xxmc, $njmc, $xnxq);

        if (!$res) {
            $this->error("本行数据空");
        }

        if ($res['code']) {
            $this->success($res['msg'], '', $res['data']);
        } else {
            $this->error($res['msg'], '', $res['data']);
        }
    }

    /**
     *  初二数据老师表和其它数据表POST
     */
    public function post_c2ls()
    {
        $ls = $this->request->param('postls/a', []);
        $sj = $this->request->param('postsj/a', []);
        //var_dump($d);

        if (empty($ls)) {
            $this->error("没有老师数据！");
        }
        if (empty($sj)) {
            $this->error("没有学年学期、周次、星期等数据！");
        }

        $njmc = 8;
        $xnxq = "";     //学年学期
        $xq = "";         //星期几
        $zc = "";             //周次

        if (isset($sj['xnxq']))          $xnxq = $sj['xnxq'];
        if (isset($sj['xq']))            $xq = $sj['xq'];
        if (isset($sj['zc']))            $zc = $sj['zc'];

        $m = new WhzxModel();
        $ret = $m->save_kc_ls($ls, $njmc, '武湖中学', $xnxq, $zc, $xq);
        //var_dump($ls);

        //保存老师到数据库
        $v_ls = array();
        foreach ($ls as $k1 => $v1) {
            if ($k1 == 0) {
                continue;
            }     //第1行数据是标题行，不要
            //var_dump($v1);
            foreach ($v1 as $k2 => $v2) {
                if ($k2 == 'bj' || $k2 == 'bzr' || $k2 == 'jswz') {
                    continue;
                }    //第1列和2列是班级名称和班主任，不要
                //var_dump($k2);
                $v_ls[] = $v2;  //保存老师到数据库里
            }
        }
        //var_dump($v_ls);
        $ret = $m->save_ls($v_ls, $njmc, '武湖中学', $xnxq, $zc, $xq);

        $res = ["code" => 1, "data" => [$ls, $sj], "msg" => ""];

        if ($res['code']) {
            $this->success($res['msg'], '', $res['data']);
        } else {
            $this->error($res['msg'], '', $res['data']);
        }
    }
    /**
     *  初二数据课表POST，一行一行地取数据
     */
    public function post_c2kb()
    {
        $kb = $this->request->param('postkb_row/a', []);        //课表是一行一行地取，否则数据太大有丢失Post数据情况
        $sj = $this->request->param('postsj/a', []);
        //var_dump($kb);

        if (empty($kb)) {
            $this->error("没有课表数据！");
        }
        if (empty($sj)) {
            $this->error("没有学年学期、周次、星期等数据！");
        }

        $njmc = 8;
        $xxmc = '武湖中学';
        $xnxq = "";     //学年学期
        $xq = "";         //星期几
        $zc = "";             //周次
        if (isset($sj['xnxq']))          $xnxq = $sj['xnxq'];
        if (isset($sj['xq']))            $xq = $sj['xq'];
        if (isset($sj['zc']))            $zc = $sj['zc'];
        //var_dump($kb);

        $m = new WhzxModel();
        $res = $m->save_kb_bj($kb, $xxmc, $njmc, $xnxq);

        if (!$res) {
            $this->error("本行数据空");
        }

        if ($res['code']) {
            $this->success($res['msg'], '', $res['data']);
        } else {
            $this->error($res['msg'], '', $res['data']);
        }
    }
    
    /**
     *  初三数据老师表和其它数据表POST
     */
    public function post_c3ls()
    {
        $ls = $this->request->param('postls/a', []);
        $sj = $this->request->param('postsj/a', []);
        //var_dump($d);

        if (empty($ls)) {
            $this->error("没有老师数据！");
        }
        if (empty($sj)) {
            $this->error("没有学年学期、周次、星期等数据！");
        }

        $njmc = 9;
        $xnxq = "";     //学年学期
        $xq = "";         //星期几
        $zc = "";             //周次

        if (isset($sj['xnxq']))          $xnxq = $sj['xnxq'];
        if (isset($sj['xq']))            $xq = $sj['xq'];
        if (isset($sj['zc']))            $zc = $sj['zc'];

        $m = new WhzxModel();
        $ret = $m->save_kc_ls($ls, $njmc, '武湖中学', $xnxq, $zc, $xq);
        //var_dump($ls);

        //保存老师到数据库
        $v_ls = array();
        foreach ($ls as $k1 => $v1) {
            if ($k1 == 0) {
                continue;
            }     //第1行数据是标题行，不要
            //var_dump($v1);
            foreach ($v1 as $k2 => $v2) {
                if ($k2 == 'bj' || $k2 == 'bzr' || $k2 == 'jswz') {
                    continue;
                }    //第1列和2列是班级名称和班主任，不要
                //var_dump($k2);
                $v_ls[] = $v2;  //保存老师到数据库里
            }
        }
        //var_dump($v_ls);
        $ret = $m->save_ls($v_ls, $njmc, '武湖中学', $xnxq, $zc, $xq);

        $res = ["code" => 1, "data" => [$ls, $sj], "msg" => ""];

        if ($res['code']) {
            $this->success($res['msg'], '', $res['data']);
        } else {
            $this->error($res['msg'], '', $res['data']);
        }
    }
    /**
     *  初三数据课表POST，一行一行地取数据
     */
    public function post_c3kb()
    {
        $kb = $this->request->param('postkb_row/a', []);        //课表是一行一行地取，否则数据太大有丢失Post数据情况
        $sj = $this->request->param('postsj/a', []);
        //var_dump($kb);

        if (empty($kb)) {
            $this->error("没有课表数据！");
        }
        if (empty($sj)) {
            $this->error("没有学年学期、周次、星期等数据！");
        }

        $njmc = 9;
        $xxmc = '武湖中学';
        $xnxq = "";     //学年学期
        $xq = "";         //星期几
        $zc = "";             //周次
        if (isset($sj['xnxq']))          $xnxq = $sj['xnxq'];
        if (isset($sj['xq']))            $xq = $sj['xq'];
        if (isset($sj['zc']))            $zc = $sj['zc'];
        //var_dump($kb);

        $m = new WhzxModel();
        $res = $m->save_kb_bj($kb, $xxmc, $njmc, $xnxq);

        if (!$res) {
            $this->error("本行数据空");
        }

        if ($res['code']) {
            $this->success($res['msg'], '', $res['data']);
        } else {
            $this->error($res['msg'], '', $res['data']);
        }
    }
}
